from django.shortcuts import render
from rest_framework.decorators import authentication_classes, permission_classes

# method_decorator 给装饰器自动添加 self
from django.utils.decorators import method_decorator
from utils.unidt_decortator import base_decorator
# Create your views here.
from rest_framework.views import APIView
from django.contrib.auth.models import User
from django.forms.models import model_to_dict
from rest_framework.response import Response
from rest_framework import status

# 缓存装饰器
from django_api_cache import api_cache

# APIView
class HomeApiView(APIView):
    def __init__(self):
        super(HomeApiView, self).__init__()

    def get_view_name(self):
        return "门户页"

    @authentication_classes([])
    @permission_classes([])
    @method_decorator(api_cache(timeout=60, cache="unidt-redis", header_key='Authorization', body_data=False))
    def get(self, request):
        user_qs = User.objects.filter(id=1).values("username").first()['username']
        return render(request, "base_config/index.html", locals())


# 门户
# @method_decorator(base_decorator)
# def get_home(request):
#
#     return render(request, "base_config/index.html", locals())